const Response = require('@/utils/response');
const LinkCategoryService = require('@/service/link/category');

class LinkCategoryController {
  async getCategories(ctx) {
    const params = ctx.request.body;
    const res = await LinkCategoryService.getCategories(params);
    return Response.success(ctx, res, '获取分类列表成功');
  }

  async getAllCategories(ctx) {
    const res = await LinkCategoryService.getAll();
    return Response.success(ctx, res, '获取所有分类成功');
  }

  async saveCategory(ctx) {
    const params = ctx.request.body;
    if (!params.name) return Response.error(ctx, '分类名称不能为空', 400);
    const res = await LinkCategoryService.saveCategory(params);
    return Response.success(ctx, res, '保存分类成功');
  }

  async deleteCategory(ctx) {
    const { id } = ctx.request.body;
    if (!id) return Response.error(ctx, '分类ID不能为空', 400);
    const res = await LinkCategoryService.deleteCategory(id);
    return Response.success(ctx, res, '删除分类成功');
  }
}

module.exports = new LinkCategoryController();